
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
</head>
<body>
	<script>
//17.写一个方法实现传入一个字符串金额，加上千位分隔符
//10，000.23
function moneyFormat(numStr){
    let xiaoshu = numStr.split(".")[1] || "";//获取小数部分 [23]
    let zhengshu = numStr.split(".")[0].split("").reverse();//整数部分变成倒叙数组[0,0,0,0,1]
    let tempArr=[];
    zhengshu.forEach((item,index)=>{
        tempArr.push(item);
        if(index%3==2 && index <zhengshu.length){
            tempArr.push(",");
        }
    })
    var nexNum = tempArr.reverse().join("");
    console.log("xiaoshu是：",typeof xiaoshu,xiaoshu)
    if(xiaoshu !=" "){
        xiaoshu="."+xiaoshu;
    }
    let finalMoney=nexNum+xiaoshu ;
    return  finalMoney
}
var strMoney= "9999678.32";
var strMoney= "9999678000000";
console.log("17.测试货币格式转化的方法：",moneyFormat(strMoney))

	</script>
	
</body>
</html>